home *** CD-ROM | disk | FTP | other *** search
/ Apple II Magazines (PO) / Nibble Volume 13, No. 01 (1992-01)(MindCraft Publishing)(Side A)[a].zip / Nibble Volume 13, No. 01 (1992-01)(MindCraft Publishing)(Side A)[a].po / SCREEN.CMD.S < prev    next >
Text File  |  1996-12-24  |  20KB  |  594 lines

  1. ********************************
  2. *         SCREEN.CMD.S         *
  3. * Screen Commander source code *
  4. *         by Paul Esser        *
  5. *                              *
  6. *    Copyright (C) 1991 by     *
  7. *  MindCraft Publishing Corp.  *
  8. *      Lincoln, MA  01773      *
  9. *                              *
  10. *       EDASM assembler        *
  11. ********************************
  12. *------------------
  13. *     EQUATES
  14. *------------------
  15. * Filetypes used by TSAVE/TLOAD
  16. *
  17. SCR40TYPE EQU $F4        ;40-column TSAVE/TLOAD file type
  18. SCR80TYPE EQU $F8        ;80-column    "     "    "   "
  19. OURAUXID  EQU $0400      ;Auxillary type for both of the above
  20. *
  21. * Zero page storage
  22. *
  23. PTR       EQU $06        ;pointer ($6,7)
  24. PADDR     EQU $08        ;storage for address returned by GETBUFR
  25. BAS1L     EQU $06        ;temp storage for screen base address--
  26. BAS1H     EQU $07        ;(don't want to erase BASL/BASH at $28/29)
  27. *
  28. * Applesoft
  29. *
  30. HIMEM     EQU $73        ;Applesoft HIMEM ($73,74)
  31. *
  32. * Keyboard/Screen
  33. *
  34. KEY       EQU $C000      ;keyboard
  35. STROBE    EQU $C010      ;clear keyboard strobe
  36. STORE80ON EQU $C001      ;use PAGE2 to switch between main/aux mem
  37. RDCHARSET EQU $C01E      ; >=$80: alternate charset (INV/MouseText)
  38. RDCOL80   EQU $C01F      ; >=$80: 80 column screen active
  39. PAGE2OFF  EQU $C054      ;select main memory (when STORE80 is ON)
  40. PAGE2ON   EQU $C055      ;select aux memory
  41. *
  42. * Monitor
  43. *
  44. CH        EQU $24        ;horiz. position of cursor
  45. OPLEN     EQU $2F        ;opcode length returned by CHKOPLEN
  46. CSWL      EQU $36        ;char output address
  47. CSWH      EQU $37
  48. KSWL      EQU $38        ;char input address
  49. KSWH      EQU $39
  50. A1L       EQU $3C        ;Move start
  51. A1H       EQU $3D
  52. A2L       EQU $3E        ;Move end
  53. A2H       EQU $3F
  54. A4L       EQU $42        ;Move destination
  55. A4H       EQU $43
  56. INBUF     EQU $200       ;input buffer, used for temp storage
  57. CHKOPLEN  EQU $F88E      ;check opcode length
  58. COUT      EQU $FDED      ;char output
  59. MOVE      EQU $FE2C      ;Monitor Move routine
  60. *
  61. * BI Global Page
  62. *
  63. EXTRNCMD  EQU $BE06      ;external command vector
  64. ERROUT    EQU $BE09      ;output BASIC.SYSTEM error
  65. STATE     EQU $BE42      ;nonzero: BASIC program is running
  66. XTRNADDR  EQU $BE50      ;external command address
  67. XLEN      EQU $BE52      ;external command length minus 1
  68. XCNUM     EQU $BE53      ;0 for external command
  69. PBITS     EQU $BE54      ;permitted parameter bits
  70. FBITS     EQU $BE56      ;found parameter bits
  71. VPATH1    EQU $BE6C      ;primary pathname or command name
  72. GOSYSTEM  EQU $BE70      ;do MLI call
  73. CRACESS   EQU $BEA3      ;CREATE access byte
  74. CRFILID   EQU $BEA4      ;CREATE file type
  75. CRAUXID   EQU $BEA5      ;CREATE auxillary type
  76. CRFKIND   EQU $BEA7      ;CREATE file storage type
  77. SSGINFO   EQU $BEB4      ;GET/SET FILE INFO parameter count
  78. FIFILID   EQU $BEB8      ;GET/SET FILE INFO file type
  79. FIAUXID   EQU $BEB9      ;GET/SET FILE INFO auxillary type
  80. SREFNUM   EQU $BEC7      ;GET/SET MARK or EOF reference number
  81. OSYSBUF   EQU $BECE      ;OPEN system I/O buffer
  82. OREFNUM   EQU $BED0      ;OPEN returned reference number
  83. RWREFNUM  EQU $BED6      ;READ/WRITE reference num.
  84. RWDATA    EQU $BED7      ;READ/WRITE data location
  85. RWCOUNT   EQU $BED9      ;READ/WRITE amount of data
  86. CFREFNUM  EQU $BEDE      ;CLOSE/FLUSH reference num.
  87. GETBUFR   EQU $BEF5      ;Allocate memory from BASIC.SYSTEM
  88. *
  89. * ProDOS Global Page
  90. *
  91. MACHID    EQU $BF98      ;Machine ID
  92. *
  93. *--------------------
  94. * INSTALLATION
  95. *--------------------
  96.           ORG $4000
  97. *
  98. * Installation/Relocation segment
  99. *  by Bill Tudor
  100. *
  101.           LDA #<PEND-PSTART+$100
  102.           JSR GETBUFR    ;get memory above HIMEM
  103.           BCC GOTBUF
  104.           JMP ERROUT
  105. GOTBUF    STA PADDR      ;save address of allocated memory space
  106.           STA MANUAL+1   ;manually relocate an opcode
  107.           LDA #>MODSTART
  108.           STA PTR        ;set PTR to start of code that requires
  109.           LDA #<MODSTART ; modification
  110.           STA PTR+1
  111. MODLOOP   LDY #0
  112.           LDA (PTR),Y    ;get an opcode
  113.           JSR CHKOPLEN   ;find opcode length
  114.           LDY OPLEN
  115.           CPY #2         ;if it's not a 3-byte opcode (Y=2),
  116.           BNE NOMOD      ; then no modification needed
  117.           LDA (PTR),Y
  118.           CMP #<PSTART   ;see if opcode's high order byte is
  119.           BLT NOMOD      ; within the program
  120.           CMP #<PEND+$100
  121.           BGE NOMOD      ;if not, no modification needed
  122.           SEC
  123.           SBC #<PSTART   ;if so, relocate it by subtracting
  124.           CLC            ; current location then adding future
  125.           ADC PADDR      ; location to high order byte
  126.           STA (PTR),Y
  127. NOMOD     TYA
  128.           SEC
  129.           ADC PTR        ;increment pointer to next opcode
  130.           STA PTR
  131.           BCC CHKDONE
  132.           INC PTR+1
  133. CHKDONE   LDA PTR+1      ;see if end of modification section
  134.           CMP #<MODEND   ; has been reached
  135.           BLT MODLOOP
  136.           LDA PTR
  137.           CMP #>MODEND   ;if not, modify some more
  138.           BLT MODLOOP
  139. *
  140.           LDA EXTRNCMD+1 ;link into external command chain
  141.           STA NXTCMD+1
  142.           LDA EXTRNCMD+2
  143.           STA NXTCMD+2
  144.           LDA #$00
  145.           STA EXTRNCMD+1
  146.           LDA PADDR
  147.           STA EXTRNCMD+2
  148. *
  149.           LDA #>PSTART   ;now move the code to the memory
  150.           STA A1L        ; reserved for it using Monitor
  151.           LDA #<PSTART   ; MOVE routine
  152.           STA A1H
  153.           LDA #>PEND
  154.           STA A2L
  155.           LDA #<PEND
  156.           STA A2H
  157.           LDA #$00
  158.           STA A4L
  159.           LDA PADDR
  160.           STA A4H
  161.           LDY #0
  162.           JSR MOVE
  163.           CLC
  164.           RTS
  165. *
  166. HEREL     EQU >*         ;fill with zeros up to next page
  167.           DS $100-HEREL,0
  168. *
  169. *---------------------
  170. * COMMAND PARSING
  171. *---------------------
  172. *
  173. PSTART    EQU *          ;start of installed portion of program
  174. MODSTART  CLD            ;start of part that has to be modified
  175.           LDA VPATH1
  176.           STA PTR        ;get pointer to command/pathname
  177.           LDA VPATH1+1   ; into page zero
  178.           STA PTR+1
  179.           LDY #0
  180. CHKTSAVE  INY            ;check for TSAVE command
  181.           LDA (PTR),Y
  182.           CMP S.TSAVE,Y  ;compare command with TSAVE
  183.           BNE NOTTSAVE   ;if no match, not TSAVE
  184.           CPY S.TSAVE    ;see if more characters to check
  185.           BLT CHKTSAVE
  186.           LDA #>J.TSAVE  ;it is TSAVE: prepare to parse
  187.           LDX #%00000001 ;set PBITS for pathname required
  188.           JMP PARSE      ;go parse it
  189. NOTTSAVE  LDY #0
  190. CHKTLOAD  INY            ;if not TSAVE, let's see if it is TLOAD
  191.           LDA (PTR),Y
  192.           CMP S.TLOAD,Y
  193.           BNE NOTTLOAD
  194.           CPY S.TLOAD
  195.           BLT CHKTLOAD
  196.           LDA #>J.TLOAD  ;it is TLOAD
  197.           LDX #%00010001 ;set PBITS for pathname optional
  198.           JMP PARSE      ;go parse it
  199. NOTTLOAD  LDY #0
  200. CHKDUMP   INY            ;if not TLOAD, our last try is DUMP
  201.           LDA (PTR),Y
  202.           CMP S.DUMP,Y
  203.           BNE NOTOURS    ;we'll give up if it is not DUMP
  204.           CPY S.DUMP
  205.           BLT CHKDUMP
  206.           LDA #>J.DUMP   ;it is DUMP
  207.           LDX #%00010001 ;set PBITS for pathname optional
  208. *
  209. PARSE     DEY            ;Set up for BASIC.SYSTEM to parse command
  210.           STY XLEN       ;set XLEN to command length minus 1
  211.           LDY #0
  212.           STY XCNUM      ;zero XCNUM to indicate external command
  213.           STA XTRNADDR   ;point XTRNADDR to particular command
  214. MANUAL    LDA #$00       ;--modified by relocator
  215.           STA XTRNADDR+1
  216.           STX PBITS      ;set PBITS according to particular command
  217.           LDX #%00000100
  218.           STX PBITS+1    ;set PBITS+1: S and D parameters allowed
  219.           CLC            ;carry clear indicates command found
  220.           RTS
  221. *
  222. NOTOURS   SEC            ;carry set indicates not our command
  223. NXTCMD    JMP $0000      ;--modified to point to other ext. cmds.
  224. *
  225. *----------------------
  226. * COMMAND HANDLERS
  227. *----------------------
  228. *
  229. J.TSAVE   JMP TSAVE      ;jump table used for each command
  230. J.TLOAD   JMP TLOAD      ; handler because relocator assumes all
  231. J.DUMP    JMP DUMP       ; three commands start on same page
  232. *
  233. * TSAVE command handler
  234. *
  235. TSAVE     JSR SCRMODE    ;get screen mode (40 or 80 col.)
  236.           LDA FILETYPE
  237.           LDX #>OURAUXID
  238.           LDY #<OURAUXID ;create file using TSAVE/TLOAD filetype
  239.           JSR CREATE     ; and auxillary type
  240.           BCC TSAVE1
  241.           CMP #$13       ;ignore "DUPLICATE FILE NAME" error, we'll
  242.           BNE ERROR      ; just write on top of old file
  243. TSAVE1    JSR GETFILE    ;verify file and open it
  244.           BCS ERROR      ;error exit
  245.           JSR RWSETUP    ;set up R/W parms, start at top of screen
  246. TSAVE2    JSR GETLINE    ;get a text screen line into INBUF
  247.           LDA #$CB       ;and write it to disk with MLI WRITE call
  248.           JSR GOSYSTEM
  249.           BCS ERROPEN    ;close and exit if error
  250.           INC LINECOUNT  ;move down to next screen line
  251.           LDA LINECOUNT
  252.           CMP #24        ;continue until all 24 screen lines done
  253.           BNE TSAVE2
  254.           LDA #$CF
  255.           JSR GOSYSTEM   ;GET_MARK followed by SET_EOF:
  256.           BCS ERROPEN    ; in case the file somehow started out
  257.           LDA #$D0       ; larger than needed for text screen,
  258.           JSR GOSYSTEM   ; this cuts off unused portion of file
  259.           BCC CLOSE
  260. *
  261. ERROPEN   PHA            ;Error while file is open:
  262.           LDA #$CC       ; save error code on stack and close file
  263.           JSR GOSYSTEM
  264.           PLA
  265. ERROR     SEC            ;Error: return to BI with carry set
  266.           RTS            ; and error code in A reg.
  267. *
  268. * TLOAD command handler
  269. *
  270. TLOAD     LDA FBITS      ;check bit 0 of FBITS to see if
  271.           AND #$01       ; a pathname was specified
  272.           BNE TLOAD1     ;if no pathname, do nothing, just return
  273.           CLC            ; to BASIC with carry clear (no error)
  274.           RTS
  275. TLOAD1    JSR SCRMODE    ;get screen mode
  276.           JSR GETFILE    ;verify file and open it
  277.           BCS ERROR      ;error exit
  278.           JSR RWSETUP    ;set up R/W parms, start at top of screen
  279. TLOAD2    LDA #$CA       ;read a screen line from disk into INBUF
  280.           JSR GOSYSTEM   ; with MLI READ call
  281.           BCS ERROPEN
  282.           JSR PUTLINE    ;and put it on the text screen
  283.           INC LINECOUNT
  284.           LDA LINECOUNT  ;do all 24 screen lines this way
  285.           CMP #24
  286.           BNE TLOAD2
  287. *
  288. CLOSE     LDA #$CC       ;exit to BASIC via close
  289.           JMP GOSYSTEM
  290. *
  291. * DUMP command handler
  292. *
  293. DUMP      JSR SCRMODE    ;get screen mode
  294.           LDA FBITS
  295.           AND #$01       ;check FBITS to see if pathname specified,
  296.           BEQ PRDUMP     ; if not then dump to printer
  297.           LDA #$04
  298.           STA FILETYPE   ;create a text file (filetype = 4)
  299.           LDX #0         ; (auxillary type = 0, not a random-access
  300.           LDY #0         ;  file)
  301.           JSR CREATE
  302.           BCS ERROR
  303.           JSR OPEN       ;open file
  304.           BCS ERROR      ;error exit
  305.           JSR RWSETUP    ;set up R/W, start at top line
  306.           INC RWCOUNT    ;add 1 to write count for carriage return
  307. DUMP2     JSR GETLINASC  ;get a screen line & convert to ASCII text
  308.           LDA #$CB       ;then write it to disk
  309.           JSR GOSYSTEM
  310.           BCS ERROPEN
  311.           INC LINECOUNT
  312.           LDA LINECOUNT  ;do 24 lines
  313.           CMP #24
  314.           BNE DUMP2
  315.           JMP CLOSE      ;then close file
  316. *
  317. * Printer Dump
  318. *  by Robert Heath
  319. *
  320. PRDUMP    LDA CSWL       ;save current input/output device
  321.           PHA
  322.           LDA CSWH
  323.           PHA
  324.           LDA KSWL
  325.           PHA
  326.           LDA KSWH
  327.           PHA
  328.           LDA CH         ;save current cursor location
  329.           PHA            ; (CH is modified by printer card)
  330.           LDA PRINTER    ;set output to printer slot
  331.           STA CSWH
  332.           LDA #0
  333.           STA CSWL
  334.           STA LINECOUNT  ;start at top screen line
  335.           TAX
  336. INIT      LDA INITSTR,X  ;first send init. string to printer card
  337.           BEQ PRLINE
  338.           JSR COUT
  339.           INX
  340.           BNE INIT
  341. PRLINE    LDA KEY        ;check for ESC or Ctrl-C keys, exit
  342.           CMP #$9B       ; if either pressed
  343.           BEQ ESC
  344.           CMP #$83
  345.           BEQ CTRLC
  346.           JSR GETLINASC  ;get screen line, convert to ASCII text
  347.           LDX #0
  348. PRLINE1   LDA INBUF,X    ;then send it to printer
  349.           ORA #$80
  350.           JSR COUT
  351.           INX
  352.           CPX SCRWIDTH
  353.           BLT PRLINE1
  354.           BEQ PRLINE1    ;(carriage return included at end of line)
  355.           INC LINECOUNT
  356.           LDA LINECOUNT
  357.           CMP #24        ;do all 24 lines
  358.           BNE PRLINE
  359. EXIT      PLA            ;then restore original I/O device
  360.           STA CH         ;and I/O device
  361.           PLA
  362.           STA KSWH
  363.           PLA
  364.           STA KSWL
  365.           PLA
  366.           STA CSWH
  367.           PLA
  368.           STA CSWL
  369.           CLC            ;indicate no error
  370.           RTS
  371. *
  372. CTRLC     LDA STATE      ;Ctrl-C or ESC:  Abort printer dump.
  373.           BNE EXIT       ;Usually clear keyboard, except when
  374. ESC       STA STROBE     ; ctrl-c pressed within running BASIC
  375.           JMP EXIT       ; program, so ctrl-c stops program as well
  376. *
  377. *
  378. * SUBROUTINES USED BY COMMAND HANDLERS
  379. *
  380. * Get screen display mode (40/80 columns, primary/alternate char. set)
  381. *
  382. SCRMODE   LSR CHARSET    ;start by assuming 40-column mode and
  383.           LDX #SCR40TYPE ; primary character set until proven
  384.           LDY #40        ; otherwise
  385.           LDA MACHID
  386.           AND #%11100010 ;check for IIe/IIc/IIc+/IIgs and presence
  387.           CMP #%10100010 ; of 80-column card and 64K minimum,
  388.           BNE SM2        ; if not then must be 40 column mode
  389.           LDA RDCHARSET  ;check for alternate character set
  390.           BPL SM1        ; (alt. set has inverse lowercase $60-7F)
  391.           SEC            ; if so, set bit 7 of CHARSET flag
  392.           ROR CHARSET
  393. SM1       LDA RDCOL80    ;check for 80 column mode
  394.           BPL SM2        ; if not, skip
  395.           STA STORE80ON  ;The STORE80ON and PAGE2OFF soft switches
  396.           STA PAGE2OFF   ; should be on already, but just in case..
  397.           LDX #SCR80TYPE ;It is 80 column mode
  398.           LDY #80
  399. SM2       STX FILETYPE   ;save FILETYPE and SCRWIDTH variables
  400.           STY SCRWIDTH   ; according to screen mode (40/80)
  401.           RTS
  402. *
  403. * Create a file
  404. *
  405. CREATE    STA CRFILID    ;Areg = filetype desired
  406.           STX CRAUXID    ;(Xlo,Yhi) = auxillary type desired
  407.           STY CRAUXID+1
  408.           LDA #1
  409.           STA CRFKIND    ;make it standard file (not subdirectory)
  410.           LDA #$C3
  411.           STA CRACESS    ;make it unlocked
  412.           LDA #$C0
  413.           JMP GOSYSTEM   ;go create it
  414. *
  415. * Get a line from the screen and stuff it in INBUF
  416. *
  417. GETLINE   JSR BAS1CALC   ;get base address of current screen line
  418.           LDA SCRWIDTH
  419.           CMP #80        ;if 80 column mode, use GETLINE80
  420.           BEQ GETLINE80
  421.           LDY #39        ;40 column mode: copy 40 bytes from screen
  422. GL1       LDA (BAS1L),Y  ; base address to INBUF
  423.           STA INBUF,Y
  424.           DEY
  425.           BPL GL1
  426.           RTS
  427. GETLINE80 LDX #79        ;80 column mode: alternate 40 main memory
  428.           LDY #39        ; bytes with 40 auxillary memory bytes
  429. GL2       LDA (BAS1L),Y  ; from screen base address, and put into
  430.           STA INBUF,X    ; 80-byte area at INBUF
  431.           DEX
  432.           PHP
  433.           SEI            ;(no interruptions when aux. memory on)
  434.           STA PAGE2ON
  435.           LDA (BAS1L),Y
  436.           STA INBUF,X    ;Note: Auxillary memory bytes are in even
  437.           STA PAGE2OFF   ;  columns 0-78.
  438.           PLP            ; Main memory bytes are in odd
  439.           DEX            ;  columns 1-79.
  440.           DEY
  441.           BPL GL2
  442.           RTS
  443. *
  444. * Get a line into INBUF and convert to ASCII characters $20-7E
  445. *
  446. GETLINASC JSR GETLINE    ;First get the line into INBUF
  447.           LDX #0
  448. GLA1      LDA INBUF,X    ;get screen byte
  449.           BMI GLA2
  450.           BIT CHARSET    ;if it is flashing ($40-7F, primary char.
  451.           BMI GLA2       ;  set only), then convert it to
  452.           AND #$3F       ; inverse ($00-3F)
  453. GLA2      AND #$7F       ;Clear high bit
  454.           CMP #$7F       ;If del character $7F (checkerboard box),
  455.           BNE GLA3       ; convert it to a space ($20) because
  456.           LDA #$20       ; many printers can't print it
  457. GLA3      CMP #$20       ;Convert $00-1F (inverse uppercase) to
  458.           BCS GLA4       ; ASCII uppercase ($40-5F)
  459.           ORA #$40
  460. GLA4      STA INBUF,X    ;store modified byte
  461.           INX
  462.           CPX SCRWIDTH   ;do all 40 or 80 screen bytes in the line
  463.           BNE GLA1
  464.           LDA #$0D       ;add a carriage return ($0D)
  465.           STA INBUF,X    ; to the end of the line
  466.           RTS
  467. *
  468. * Put a line onto the screen from INBUF
  469. *
  470. PUTLINE   JSR BAS1CALC   ;Works same as GETLINE except it performs
  471.           LDA SCRWIDTH   ; reverse action--moves INBUF to screen
  472.           CMP #80
  473.           BEQ PUTLINE80
  474.           LDY #39
  475. PL1       LDA INBUF,Y
  476.           STA (BAS1L),Y
  477.           DEY
  478.           BPL PL1
  479.           RTS
  480. PUTLINE80 LDX #79
  481.           LDY #39
  482. PL2       LDA INBUF,X
  483.           STA (BAS1L),Y
  484.           DEX
  485.           PHP
  486.           SEI
  487.           STA PAGE2ON
  488.           LDA INBUF,X
  489.           STA (BAS1L),Y
  490.           STA PAGE2OFF
  491.           PLP
  492.           DEX
  493.           DEY
  494.           BPL PL2
  495.           RTS
  496. *
  497. * Calculate screen base address, given LINECOUNT = screen line count
  498. *
  499. BAS1CALC  LDA LINECOUNT  ;Given vtab (0-23), calculate screen base
  500.           PHA            ; address
  501.           LSR A
  502.           AND #$03       ;Works same as Monitor routine BASCALC
  503.           ORA #$04       ; ($FBC1), except stores result in
  504.           STA BAS1H      ; BAS1L,BAS1H ($6,7) instead of
  505.           PLA            ; BASL,BASH ($28,29).
  506.           AND #$18
  507.           BCC BC1
  508.           ADC #$7F
  509. BC1       STA BAS1L
  510.           ASL A
  511.           ASL A
  512.           ORA BAS1L
  513.           STA BAS1L
  514.           RTS
  515. *
  516. * Set up READ/WRITE parameters, and initialize LINECOUNT to 0 (top line)
  517. *
  518. RWSETUP   LDA #>INBUF
  519.           STA RWDATA
  520.           LDA #<INBUF    ;R/W data area is INBUF ($200)
  521.           STA RWDATA+1
  522.           LDA SCRWIDTH   ;R/W count is 40 or 80 bytes depending
  523.           STA RWCOUNT    ; on screen mode (40/80 columns)
  524.           LDA #0
  525.           STA RWCOUNT+1
  526.           STA LINECOUNT  ;zero LINECOUNT to start at top line
  527.           RTS
  528. *
  529. * Get file info to make sure it is a screen file, then open it
  530. *
  531. GETFILE   LDA #$0A       ;set up GET_FILE_INFO parameter count
  532.           STA SSGINFO
  533.           LDA #$C4       ;do GET_FILE_INFO call
  534.           JSR GOSYSTEM
  535.           BCS GETERR     ;exit if error
  536.           LDA FIFILID
  537.           CMP FILETYPE   ;verify proper filetype ($F4 or $F8
  538.           BNE TYPEMIS    ; depending on 40/80 column mode)
  539.           LDA FIAUXID    ;if wrong type then "FILE TYPE MISMATCH"
  540.           CMP #>OURAUXID ; error will be reported
  541.           BNE TYPEMIS
  542.           LDA FIAUXID+1  ;also verify proper auxillary type ($0400)
  543.           CMP #<OURAUXID ;if filetype & auxtype OK, then
  544.           BNE TYPEMIS    ; fall through to OPEN routine
  545. *
  546. * Open file
  547. *
  548. OPEN      LDA HIMEM      ;use general purpose I/O buffer at HIMEM
  549.           STA OSYSBUF    ; for OPEN command
  550.           LDA HIMEM+1
  551.           STA OSYSBUF+1
  552.           LDA #$C8       ;do OPEN call
  553.           JSR GOSYSTEM
  554.           BCS GETERR     ;exit if error
  555.           LDA OREFNUM
  556.           STA RWREFNUM   ;copy reference number returned by OPEN
  557.           STA SREFNUM    ; to R/W, EOF/MARK, and CLOSE/FLUSH
  558.           STA CFREFNUM   ; parameter lists
  559.           CLC            ;indicate no error
  560.           RTS
  561. TYPEMIS   LDA #$0D       ;Type Mismatch error code
  562. GETERR    SEC            ;indicate error occurred
  563.           RTS
  564. *
  565. *
  566. MODEND    EQU *          ;everything following doesn't get modified
  567. *
  568. *
  569. * CONSTANTS
  570. *
  571.           MSB OFF        ;ASCII characters now have high bit off
  572. S.TSAVE   STR 'TSAVE'    ;Command strings (begin with length byte)
  573. S.TLOAD   STR 'TLOAD'
  574. S.DUMP    STR 'DUMP'
  575. *
  576.           MSB ON         ;ASCII characters now have high bit on
  577. INITSTR   DFB $8D,$8D,$89 ;Printer init string
  578.           ASC '82N'      ; sets line length to 81 characters and
  579.           DFB $8D,$8D    ;prints a few blank lins
  580.           DFB $8D,$8D,$00
  581. *
  582. PRINTER   DFB $C1        ;printer slot: change to $Cn for slot n
  583. *
  584. *
  585. * VARIABLE STORAGE
  586. *
  587. FILETYPE  DFB 0          ;filetype expected by GETFILE routine
  588. SCRWIDTH  DFB 0          ;screen width: 40 or 80
  589. CHARSET   DFB 0          ;flag for primary/alt. char set (bit 7)
  590. LINECOUNT DFB 0          ;vtab line count, vary from 0 to 23
  591. *
  592. PEND      DFB 0          ;end of program
  593. *
  594.